<?php

use Biz\model\Album\AlbumListModel;
use  Biz\service\Album\AlbumListService;
use  Doraemon\cache\AlbumCounter;
use Doraemon\tools\IdParse;

class HeadAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $album_id = $this->getRequest()->getPost('album_id', 0);
        $is_force_show = $this->getRequest()->getPost('is_force_show', 0);//是否支持预览（1：预览 ）
        if (empty($album_id)) {
            throw new Exception('album_id参数缺失');
        }
        $info = $this->getInfo($album_id, $is_force_show);
        if (empty($info)) {
            throw new Exception('此清单已被删除', self::CODE_ERROR_VIEW_TOSTA);
        }
        $this->setSuccess($info);
    }

    public function getInfo($albumId, $is_force_show)
    {
        $albumUid = IdParse::getUid($albumId);
        $info = AlbumListService::getAlbumByAlbumId($albumId);
        if ($info) {
            switch ($info['status']) {
                case AlbumListModel::STATUS_DELETE:
                    return [];
                    break;
                case AlbumListModel::STATUS_USER_PRIVATE:
                case AlbumListModel::STATUS_PRIVATE:
                    if (!$is_force_show && $this->uid != $albumUid) {//仅自己才能看
                        return [];
                    }
                    break;
            }
            if ($this->uid > 0 && in_array($info['status'], AlbumListModel::STATS_PUBLIC_SHOW_MAP)) {
                AlbumCounter::increaseAlbumCounter($albumId, AlbumCounter::ACT_READ);
            }
        }
        return $info;
    }
}